<template>
  <el-dialog
      v-el-drag-dialog="{ drag: true, full: false, resize: false }"
      title="审核不通过"
      width="30%"
      :close-on-click-modal="false"
      :visible.sync="md.state"
      @close="closeMd"
      v-if="md.state"
  >
    <el-form :model="fm.ps" ref="formRef" :label-width="'100px'">
      <el-form-item
          label="不通过理由"
          prop="reamrk"
          :rules="[{ required: true, message: '请输入不通过事由', trigger: 'blur' }]">
        <el-input
            type="textarea"
            maxlength="500"
            show-word-limit
            :autosize="{ minRows: 3, maxRows: 7 }"
            placeholder="请输入不通过事由" v-model="fm.ps.reamrk"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit" :disabled="fm.sb.load">{{ fm.sb.text }}</el-button>
        <el-button @click="closeMd">关闭</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import elDragDialog from "@/directive/el-drag-dialog";
import {checkLeave} from "@/api/services/personMan.service";


export default {
  name: "CheckLeaveType",
  directives: {elDragDialog},
  props: ["state", "data"],
  components: {},
  data() {
    return {
      md: {state: this.state},
      fm: {
        fname: "addGroupFm",
        ps: {
          id: '',
          state: '2',
          reamrk: '',
        },
        sb: {
          load: false,
          text: "添加",
        },
      },
      loading: false,
    };
  },
  created() {
    if (this.data) {
      this.fm.ps.id = this.data.id
    }
  },
  methods: {

    /* 关闭弹框 */
    closeMd() {
      this.$emit("getMdState", false);
    },

    onSubmit() {
      this.$refs.formRef.validate((valid) => {
        if (valid) {
          this.fm.sb.load = true; // 添加按钮禁用效果
          let loading = this.U.qloading("提交中，请稍后..."); // 添加遮
          checkLeave(this.fm.ps).then((res) => {
            this.fm.sb.load = false; // 取消按钮禁用效果
            this.U.qclose(loading); // 关闭遮罩
            if (!res || res.code !== 1) {
              this.U.qerror(res.msg);
            } else {
              this.U.qsuccess(res.msg);
              this.closeMd();
              this.$emit("reloadDg");
            }
          }).catch(() => {
            this.U.qclose(loading);
          })
        }
      });
    },
  },
};
</script>